<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<c:set var="contextPath" value="${pageContext.request.contextPath}"></c:set>
<%--<jsp:include page="../../head.jsp"/>--%>
<title>维护收单行 - 云超市</title>
<div class="row" style="margin-top: 30px;">
<div class="col-sm-2"></div>
<div class="col-sm-6" id="app">
	<form class="form-horizontal" role="form">
		<div class="form-group">
			<span for="inputUserPhone" style="text-align: center;color: #f59e00" class="col-sm-12">
				<%--提示：只可以维护六盘水用户，收单行根据不同时期而定--%>
			</span>
		</div>
		<div class="form-group">
			<label for="inputUserPhone"  class="col-sm-3 control-label">专卖证号：</label>
			<div class="col-sm-9">
				<input type="text" class="form-control" v-model="selectCustCode" maxlength="12" id="inputUserPhone"
					placeholder="输入需要维护收单行的专卖证号">
			</div>
		</div>
		<div class="form-group">
			<label class="col-sm-3 control-label">收单行：</label>
			<div class="col-sm-9">
				<select class="form-control" id="userRoleSelect" v-model="selectBank">
					<option name="userRole" value="0">--请选择收单行--</option>
					<%--<option name="userRole" selected value="YYT3017">六盘水邮储</option>--%>
					<%--<option nane="userRole" value="YYT3002">六盘水农行</option>--%>
					<option v-for="bank in banks" :value="bank.value">{{bank.name}}</option>

				</select>
			</div>
		</div>
		<div style="color:red;margin-top: 7px;text-align: right;">{{hint}}</div>
		<div class="form-group">
			<div class="col-sm-offset-9 col-sm-4">
				<button style="margin-top: 10px; margin-left: 25px;" type="button"  v-show="btnshow" @click="confrimAction" class="btn btn-success btn-sm">提交维护</button>
			</div>
		</div>
	</form>
</div>
<div class="col-sm-3">

</div>
</div>
<script src="${contextPath}/static/statistics/js/vue.js"></script>
<script type="text/javascript">
    var app = new Vue({
        el: '#app',
        data: {
            selectCustCode: '',
            selectBank : '0',
            hint: '',
            banks:[],
            btnshow : true,
        },
        methods: {
			updateBanks: function(custCode) {
				var pri = custCode.substring(0,4);
				console.log(pri);
				var banks=[];
				switch (pri) {
					case  '5202':
						banks = [
                            // {name:"六盘水邮储",value:{bankMerCode:'100702044580010',bankCode:"YYT3017",areaCode:'0858'}},
                            {name:"六盘水农行",value:{bankMerCode:'103520244589709',bankCode:"YYT3002",areaCode:'0858'}},
                        ];
					    break;
					case  '5203':
                        banks = [
                            {name:"遵义农行",value:{bankMerCode:'103520344589002',bankCode:"YYT2002",areaCode:'0852'}},
                            {name:"遵义交行",value:{bankMerCode:'301703044580001',bankCode:"YYT2005",areaCode:'0852'}}
                        ];
					    break;
					case  '5204':
                        banks = [
                            {name:"安顺工行",value:{bankMerCode:'102711044580001',bankCode:"YYT7001",areaCode:'0853'}},
                            {name:"安顺农商行",value:{bankMerCode:'936711044580001',bankCode:"YYT7016",areaCode:'0853'}},
                        ];
					    break;
					case  '5206':
					case  '5222':
                        banks = [
                            {name:"铜仁工行",value:{bankMerCode:'102705044580001',bankCode:"YYT4001",areaCode:'0856'}},
                            {name:"铜仁建行",value:{bankMerCode:'105705044580001',bankCode:"YYT4003",areaCode:'0856'}},
                        ];
					    break;
                    case  '5226':
                        banks = [
                            {name:"黔东南农行",value:{bankMerCode:'103522644580000',bankCode:"YYT8001",areaCode:'0855'}},
                            {name:"黔东南工行",value:{bankMerCode:'102522644580001',bankCode:"YYT8002",areaCode:'0855'}},
                        ];
                        break;
                    case  '5201':
                        banks = [
                            {name:"贵阳银行",value:{bankMerCode:'12210120030002896',bankCode:"YYT1015",areaCode:'0851'}},
                        ];
                        break;
					default :
                        this.hint = "暂不支持维护该地区";

				}
				this.banks = banks;
			},
            confrimAction : function () {
                var myreg = /^[0-9]{12}$/;
                if(!myreg.test(this.selectCustCode)){
                    this.hint = "专卖证号无效，请检查";
                    return;
                }

                if(this.selectBank=='0'){
                    //alert("请选择要修改的角色");
                    this.hint = "请选择要维护的收单行";
                    return;
                }

                this.hint = "正在处理，请等待结果...";
                this.btnshow = false;
                var vm = this;

                var udata = {};
                udata.custCode = this.selectCustCode;
                udata.bankCode=this.selectBank.bankCode;
                udata.bankMerCode=this.selectBank.bankMerCode;
                udata.areaCode=this.selectBank.areaCode;
                debugger
                $.ajax({
                    url : "${contextPath}/sys/clouderp/bankMaintain",
                    dataType : "json",
                    type : "post",
                    data : {stringMap:udata},
                    async : false,
                    success : function(data){
                        vm.hint= data.message;
                        vm.btnshow = true;
                    },
                    error : function(result){
                        vm.hint = "服务器错误,请刷新页面重试";
                        vm.btnshow = true;
                    }
                });
            }
        },
		watch: {
            selectCustCode : function (newValue) {
                this.selectBank = '0';
                this.banks = [];
                var myreg = /^[0-9]{12}$/;
                if(!myreg.test(newValue)){
					this.hint = "请输入12位有效专卖证号";
					return;
                }
                this.hint = "";
                this.updateBanks(newValue);

            }

		}
    });
</script>


